package main_com.mapper;

import main_com.pojo.LookDateBean;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface DateMapper {

    @Select("select date, thing from date where userName=#{userName} and date=#{date}")
    LookDateBean getDateByDateAndUserName(String date, String userName);

    @Select("select date, thing from date where userName=#{userName}")
    ArrayList<LookDateBean> getDateByUserName(String userName);

    @Select("select count(*) from date where userName=#{userName} and date=#{date}")
    int findDateByDateAndUserName(String date, String userName);

    @Insert("insert into date values(#{userName}, #{date}, #{thing})")
    void insertDate(String userName, String date, String thing);

    @Delete("delete from date where userName=#{userName} and date=#{date}")
    void deleteDate(String userName, String date);

    @Update("update date set thing=#{thing} where date=#{date} and userName=#{userName}")
    void updateDate(String userName, String date, String thing);

    // 分页查询日程，根据用户名、偏移量和每页数量获取对应页的日程数据
    @Select("select date, thing from date where userName=#{userName} limit #{offset}, #{limit}")
    ArrayList<LookDateBean> getDateByUserNameWithPagination(@Param("userName") String userName, @Param("offset") int offset, @Param("limit") int limit);

    // 查询某个用户的日程总记录数，用于计算总页数
    @Select("select count(*) from date where userName=#{userName}")
    int countDateByUserName(String userName);
}
